package com.wanghlme.day27.dao.impl;

import com.wanghlme.day27.dao.IDeptDao;
import com.wanghlme.day27.pojo.Dept;
import com.wanghlme.day27.util.IRowWrapper;
import com.wanghlme.day27.util.JdbcTemplate;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class DeptDaoImpl implements IDeptDao {
    private JdbcTemplate<Dept> template;

    public DeptDaoImpl() {
        template = new JdbcTemplate<>();
    }

    private class DeptRowWrapper implements IRowWrapper<Dept> {

        @Override
        public Dept transfer(ResultSet rs) throws SQLException {
            Dept dept = new Dept();
            dept.setDeptId(rs.getInt("dept_id"));
            dept.setDeptName(rs.getString("dept_name"));
            return dept;
        }
    }

    @Override
    public Dept queryDeptById(Integer id) {
        String sql = "select dept_id, dept_name from dept where dept_id = ?";
        return template.queryForOne(sql, new Object[]{id}, new DeptRowWrapper());
    }

    @Override
    public List<Dept> listAllDept() {
        String sql = "select dept_id, dept_name from dept";
        return template.queryForList(sql, null, new DeptRowWrapper());
    }

    @Override
    public Integer insertDept() {
        return null;
    }

    @Override
    public Integer deleteDept() {
        return null;
    }

    @Override
    public Integer updateDept() {
        return null;
    }
}
